﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <script type="text/javascript">

        window.onload = function () {
            //回调函数测试
            var reg = /-([\d])([\w])/;
            var str = "asd-1dzxc";

            //replace支持回调函数， 函数的参数是exec的捕获组， 返回值是需要替换的字符串
            var str2 = str.replace(reg, function (match, num, word) {
                return match + "|" + num + "|" + word;
            })

            //把下划线转化为camlCase的形式
            reg = /-([\da-z])/g;
            var camlCase = function (all, letter) {
                return letter.toUpperCase();
            }
            str2 = "ads-2zsd-sada-123-zxcasd-12z".replace(reg, camlCase);
            console.log(str2);
        }

    </script>
</body>
</html>
